﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
@* <script src="~/lib/layui/layui.js"></script> *@

<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>权限添加</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称：</label>
            <div class="layui-input-block">
                <input type="text" name="PermissionsName" lay-verify="required" placeholder="请输入权限名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限URL：</label>
            <div class="layui-input-block">
                <input type="text" name="PermissionsUrl" lay-verify="required" placeholder="请输入URL" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                @* <button type="button" lay-on="test-iframe-curl" class="layui-btn layui-bg-red" onclick="add()">立即提交</button> *@
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>


</body>
</html>
<script>

    layui.use(['form', 'laydate', 'util'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 提交事件
        form.on('submit(demo1)', function (data) {
            var field = data.field; // 获取表单字段值
            field.State = 0;
            console.log(field);
            $.ajax({
                url: '@ViewBag.Darius'+"/api/Users/PermissionAdd",
                data: JSON.stringify(field),
                type: "post",
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    console.log(123, res);
                    if (res.code > 0) {
                        layer.alert("添加成功", {
                            title: ''
                        });
                    }
                    else {
                        alert('提交失败')
                    }
                }
            })
            // 显示填写结果，仅作演示用

            // 此处可执行 Ajax 等操作
            // …
            return false; // 阻止默认 form 跳转
        });
    });
